package dataMapper;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import dataEntity.RelativeHealthImportance;

public class RelativeHealthImportanceMapper {
	public static Map<String,Map<String,RelativeHealthImportance>> process(BufferedReader br){
		Map<String,Map<String,RelativeHealthImportance>> map = new HashMap<String,Map<String,RelativeHealthImportance>> ();
		try {
			br.readLine();
			while(br.ready()){
				RelativeHealthImportance object = buildObject(br.readLine());

				Map<String,RelativeHealthImportance> stateMap = map.get(object.getCHSI_State_Abbr());
				if(stateMap == null) stateMap = new HashMap<String,RelativeHealthImportance>();
				stateMap.put(object.getCHSI_County_Name(), object);
				map.put(object.getCHSI_State_Abbr(), stateMap);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map;
	}
	
	public static  RelativeHealthImportance buildObject(String inLine){
		String[] line = inLine.split(",");
		RelativeHealthImportance object = new RelativeHealthImportance();
		
		object.setState_FIPS_Code(line[0]);
		object.setCounty_FIPS_Code(line[1]);
		object.setCHSI_County_Name(line[2]);
		object.setCHSI_State_Name(line[3]);
		object.setCHSI_State_Abbr(line[4]);
		object.setStrata_ID_Number(line[5]);
		object.setRHI_LBW_Ind(line[6]);
		object.setRHI_VLBW_Ind(line[7]);
		object.setRHI_Premature_Ind(line[8]);
		object.setRHI_Under_18_Ind(line[9]);
		object.setRHI_Over_40_Ind(line[10]);
		object.setRHI_Unmarried_Ind(line[11]);
		object.setRHI_Late_Care_Ind(line[12]);
		object.setRHI_Infant_Mortality_Ind(line[13]);
		object.setRHI_IM_Wh_Non_Hisp_Ind(line[14]);
		object.setRHI_IM_Bl_Non_Hisp_Ind(line[15]);
		object.setRHI_IM_Hisp_Ind(line[16]);
		object.setRHI_IM_Neonatal_Ind(line[17]);
		object.setRHI_IM_Postneonatal_Ind(line[18]);
		object.setRHI_Brst_Cancer_Ind(line[19]);
		object.setRHI_Col_Cancer_Ind(line[20]);
		object.setRHI_CHD_Ind(line[21]);
		object.setRHI_Homicide_Ind(line[22]);
		object.setRHI_Lung_Cancer_Ind(line[23]);
		object.setRHI_MVA_Ind(line[24]);
		object.setRHI_Stroke_Ind(line[25]);
		object.setRHI_Suicide_Ind(line[26]);
		object.setRHI_Injury_Ind(line[27]);

		return object;
	}
}
